package main

import (
	"database/sql"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

func initializeDatabase() (err error) {
	dsn := "root:123456@tcp(localhost:3306)/tt?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := sql.Open("mysql", dsn)
	if err != nil {
		return
	}
	// 建立连接
	if err = db.Ping(); err != nil {
		log.Println("connect 2 database fail...")
		return
	}
	return nil
}

func main() {
	if err := initializeDatabase(); err != nil {
		panic(err)
	}
	log.Println("connect 2 database success.")
}
